package com.jeomo.mem.starter.mapper;

import com.jeomo.base.starter.mapper.IBaseMapper;
import com.jeomo.mem.starter.entity.MemberLevelExe;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.time.LocalDate;
import java.time.LocalDateTime;

/**
 * 会员等级执行单Mapper
 *
 * @author:Jackpot
 * @create 2021-01-14 11:25
 * @description:
 */
@Mapper
public interface MemberLevelExeMapper extends IBaseMapper<MemberLevelExe> {

    /**
     * 查询会员卡当前等级下的消费/积分信息
     * @param cardNo
     * @param levelCode
     * @param date
     * @return
     */
    @Select("select * from member_level_exe as d where d.card_no= #{cardNo} and d.level_code=#{levelCode} " +
            "and d.start_time<=#{date} and d.end_time>=#{date} ")
    MemberLevelExe queryLevelExe(@Param("cardNo") String cardNo, @Param("levelCode") String levelCode,
                                 @Param("date") LocalDateTime date);

    /**
     * 查询未处理的会员等级执行信息
     * @param cardNo
     * @param levelCode
     * @return
     */
    @Select("select * from member_level_exe as d where d.card_no= #{cardNo} and d.level_code=#{levelCode} " +
            "and d.is_rating = 0 limit 1")
    MemberLevelExe queryUntreatedLevelExe(@Param("cardNo") String cardNo, @Param("levelCode") String levelCode);
}
